<?php
namespace addon\cms\logic;
use app\common\logic\LogicBase;
use tpfcore\Core;

class MiniProgramColumn extends LogicBase
{

    public function saveMiniColumn($data){
    	$validate=Core::addonValidate($this->name);
        $validate_result = $validate->scene("add_edit")->check($data);
        if (!$validate_result) {
            return [RESULT_ERROR, $validate->getError(), null];
        }
        $result=Core::loadAddonModel($this->name)->saveObject($data);
        
        if($result){
        	return [RESULT_SUCCESS,"操作成功",url('cms/MiniColumn/index')];
        }else{
        	return [RESULT_ERROR,"操作失败",null];
        }
    }
    public function getMiniColumn($where=[]){
        return self::getList($where);
    }   
    public function delMiniColumn($data){
        $list = $this->getMiniColumn(["where"=>["id"=>$data['id']]]);

        if(isset($list[0]['img']) && is_file(".".$list[0]['img'])){
            @unlink(".".$list[0]['img']);
        }
        $result=self::deleteObject($data,true);
        if($result){
            return [RESULT_SUCCESS,"操作成功",url('cms/MiniColumn/index')];
        }else{
            return [RESULT_ERROR,"操作失败",null];
        }
    }
}